<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>upload模块快速使用</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
</head>
<body>

 <div class="layui-row layui-col-space15" style="margin-top: 30px">
     <div class="layui-col-md6">
         <div class="layui-panel">
             <button type="button" class="layui-btn" id="test1">
                 <i class="layui-icon">&#xe67c;</i>上传图片
             </button>
         </div>
     </div>
     <div class="layui-col-md6">
         <div class="layui-panel">
             <img src="" alt="" class="image" height="400" width="400">
         </div>
     </div>
 </div>

<script src="/static/layui/layui.js"></script>
<script>
    layui.use(['upload','jquery'], function(){
        var upload = layui.upload;
        var $ = layui.jquery;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '/upload/' //上传接口
            ,accept: 'file' //允许上传的文件类型
            ,done: function(res){
                //上传完毕回调
                console.log(res)
                var element = document.querySelector(".image");
                element.setAttribute("src",res.data);
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });
</script>
</body>
</html>